<template>
    <div>
          <Card>
                <p slot="title">
				    企业认证审核
			    </p>
                <div>
                    <Form class="step-form" ref="userData" :model="userData" :rules="userDataRules"  :label-width="100">
                       <Row span="12">
                            <i-col span="12" >
                                <FormItem label="企业名称：" label-position="left" :label-width="150">
                                    <Input  :disabled="hasSubmit" v-model="userData.name" type="text" placeholder="输入数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="法人姓名：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.legalPerson" type="text" placeholder="输入数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="法人身份证号：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.legalCard" type="text" placeholder="输入数据不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="法人手机号：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.legalPhone" type="text" placeholder="法人手机号不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="企业地址：" prop="address" label-position="left" :label-width="150">
                                    <Input  v-model="userData.address" type="textarea" :rows="2" placeholder="请输入企业地址" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="企业类型：" prop="partyType" label-position="left" :label-width="150">
                                   <Radio-group v-model="userData.partyType">
                                        <!--<Radio :label="1">2P</Radio>-->
                                        <Radio :label="2">4S</Radio>
                                        <Radio :label="3">监管店</Radio>
                                        <Radio :label="4">2B</Radio>
                                        <Radio :label="5">小b</Radio>
                                        <Radio :label="6">个人</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        
                        <!--2019-9-9  gyp 和前端保持一致-->
                        <!--
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="营业执照号：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.businessLicense" type="text" placeholder="营业执照号不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>-->
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="申请人真实姓名：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.applyRealName" type="text"  />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="申请人手机号：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.applyMobile" type="text" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="申请人身份证号：" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="userData.applyCarNum" type="text"  />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="用户角色：" prop="userRoles" label-position="left" :label-width="150">
                                   <Radio-group v-model="userData.userRoles">
                                        <Radio :label="1">法人</Radio>
                                        <Radio :label="2">签约代理人</Radio>
                                        <Radio :label="3">销售经理</Radio>
                                        <Radio :label="4">非企业员工</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="发布车源：" prop="is_car" label-position="left" :label-width="150">
                                   <Radio-group v-model="userData.isCar">
                                        <Radio :label="0">禁止</Radio>
                                        <Radio :label="1">允许</Radio>
                                    </Radio-group>
                                </FormItem>
                            </i-col>
                        </Row>
                        
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="营业执照号："  prop="businessLicense" label-position="left" :label-width="150">
                                    <Input  v-model="userData.businessLicense" type="text" placeholder="营业执照号不能为空" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <!--2019-9-9  gyp 和前端保持一致-->
                        <!--<Row span="12">
                            <i-col span="10">
                                <FormItem label="门头照：" label-position="left" :label-width="150">
                                    <img v-if="userData.doorHeaderUrl !== ''" :src="userData.doorHeaderUrl" height="200" width="200">
                                </FormItem>
                            </i-col>
                        </Row>-->
                        <Row span="12">
                            <i-col span="10">
                                <FormItem label="身份证正面：" label-position="left" :label-width="150">
                                    <img v-if="userData.cardUrl !== ''" :src="userData.cardUrl" height="200" width="200">
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="10">
                                <FormItem label="身份证背面：" label-position="left" :label-width="150">
                                    <img v-if="userData.cardBackUrl !== ''" :src="userData.cardBackUrl" height="200" width="200">
                                </FormItem>
                            </i-col>
                        </Row>
                        <FormItem >
                            <Button @click="auditSuccess" style="width:100px;" type="primary">审核成功</Button>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <Button @click="auditFail" style="width:100px;" >审核失败</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
            <Modal
                v-model="modal1"
                title="审核失败"
                @on-ok="ok"
                @on-cancel="cancel">
                <Input v-model="failreason" type="textarea" :rows="4" placeholder="请输入审核失败原因"/>
            </Modal>
            <Modal v-model="userRoleModel" width="360">
                <p slot="header" style="color:#f60;">
                    <Icon type="information-circled"></Icon>
                    <span>提示</span>
                </p>
                <div style="text-align:center">
                    <p style="font-size:18px;">该角色下已有用户，请核对后重新设置</p>
                </div>
                <div slot="footer">
                    <Button type="info" @click="cancel_userrole()" size="large">取消</Button>
                </div>
            </Modal>
    </div>
</template>


<script>
import ajax from '../../../libs/axios.js'
export default {
    name: 'addUser',
    data () {
        return {
            modal1:false,
            testModelShow:false,
            userRoleModel:false,
            symptomList:[],
            selectModel:[],
            userData: {
                id:'',
                name:'',
                legalPerson:'',
                legalCard:'',
                legalPhone: '',
                businessLicense:'',//营业执照号
                businessLicenseUrl:'',
                cardUrl:'',
                cardBackUrl:'',
                partyType:1,//企业类型选择
                doorHeaderUrl:'',
                applyRealName:'',//申请人真实姓名
                applyMobile:'',//申请人手机号
                applyCarNum:'',//申请人身份证号码
                address:'',//申请人的地址
                uid:'',//申请人的Id
                userRoles:0,//用户角色
                isCar:0//发车权限
            },
            hasSubmit: true,
            // 图片上传
            file: null,
            status: 'wait',
            uploadLoading: false, // 上传图片时候的加载效果,
            failreason:"",//审核失败
            userId:-1,//当前登陆人员的Id
            userName:"",//当前登陆人员的姓名
            id:-1,
            uid:'',
            userDataRules: {
                address: [
                    { required: true, message: '企业地址不能为空', trigger: 'blur'},
                    {type: 'string', max: 100, message: '不能超过100个字符', trigger: 'blur'}
                ],
                businessLicense: [
                    { required: true, message: '营业执照号不能为空', trigger: 'blur'}
                ]
            }
        }
    },
    methods: {
        // 数据初始化
        init () {
            this.userId = window.localStorage.getItem('userId')
            this.userName = window.localStorage.getItem('userName')
            this.$store.commit('setActiveName', 'partypersonalindex');
            let id = this.$route.params.id;
            this.uid = this.$route.params.userId;
            this.id = id;
            this.personalInfo(id);
        },
        // 获取数据
        personalInfo(id){
            let _that = this;
            let url = 'adminlogin/selectPartyInfoByUserId'
            let data = {
                id: _that.uid
            }
            ajax.formRes(url, data).then(res => {
                //success
                if(200 == res.code){
                    debugger
                    _that.userData = res.data;
                }else{
                    _that.$Message.success('数据原因，请联系管理员。')
                }      
            }).catch(res => {
                _that.$Message.success('数据原因，请联系管理员。')
                console.log('有错误信息')
                // fail
            })
        },
        // 审核成功相关数据操作
        auditSuccess () {
            //登陆成功，存储审核信息。
            this.addAuditInfo(2);
        },
        auditFail () {
            this.modal1 = true;
        },
        ok () {
            let _that = this;
            if(_that.failreason == ""){
                _that.$Modal.warning({
                    title: '警告',
                    content: '失败原因不能为空！！！'
                });
            }else{
                _that.addAuditInfo(3);
            }
            
        },
        cancel () {
            //this.$Message.info('点击了取消');
        },
        cancel_userrole:function(){
            this.userRoleModel = false
        },
        /*验证用户角色 */
        verificationUserRole:function(){
            let _that = this;
            return new  Promise((resolve, reject) => {
              let url = 'adminlogin/selectByPartyIdAndUserRole'
              let data = {
                  partyId:_that.userData.id,
                  userRoles: _that.userData.userRoles
              }

              ajax.formRes(url, data).then(res => {
                  debugger
                  if(res.data.length > 0){
                      resolve(false)
                  }
                  resolve(true)
              }).catch(res => {
                  console.log('有错误信息')
                  resolve(false)
              })
            })
        },
        // 存储审核信息
        addAuditInfo(status){
            let _that = this;
            _that.$refs['userData'].validate((valid) => {
                if (valid) {
                    let flag = _that.userData.userRoles
                    let result = false
                    if(flag == 1 || flag == 2){//是否需要对角色验证
                    debugger
                        _that.verificationUserRole().then(res => {
                            if(res){
                                _that.addInfo(status)
                            }else{
                                _that.userRoleModel = true
                            }
                        })
                    }else{
                        _that.addInfo(status)
                    }
                }
            })
        },
        // 存储审核信息
        addInfo(status){
            let _that = this;
            let url = 'adminlogin/addAuditInfo'
            let data = {
                uid: _that.uid,
                pId: _that.id,
                type:2,
                status:status,
                partyType:_that.userData.partyType,
                businessLicense:_that.userData.businessLicense,//营业执照号
                address:_that.userData.address,//企业地址
                userRoles:_that.userData.userRoles,//用户角色
                isCar:_that.userData.isCar,//企业地址
                remark:_that.failreason,
                auditName:_that.userName,
                            
            }
            ajax.formRes(url, data).then(res => {
                //success
                if(200 == res.code){
                    _that.$Message.success('审核成功，将为您跳转到首页。')
                    setTimeout(function () {
                        let argu = {}
                        _that.$router.push({
                            name: 'partypersonalindex',
                            params: argu
                        })
                    }, 1500)
                }else{
                    _that.$Message.success('数据原因，请联系管理员。')
                }      
            }).catch(res => {
                _that.$Message.success('数据原因，请联系管理员。')
                console.log('有错误信息')
                // fail
            })           
        }
        
    },
    created: function () {
        this.init()
    },
    activated: function () {
        //this.init()
    }
}
</script>
<style>
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .card-upload:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }
</style>

